qui(
    function (require, exports, module) {
        Director.Effect = (function () {

            var config = Director.Config;

            function init() {
                //init pagebean
                config.PageBeanEffectImage = Director.Util.createPageBean();
                config.PageBeanEffectSubtitle = Director.Util.createPageBean();
                config.PageBeanEffectAnimation = Director.Util.createPageBean();
                config.PageBeanEffectAudio = Director.Util.createPageBean();
                config.PageBeanEffectCover = Director.Util.createPageBean();
                //更新
                for (var i = 1; i <= 5; i++) {
                    getEffectList(i);
                }
                bindEffectEvent();

            }


            function getEffectList(type) {
                var entity = Director.Util.getEntity();
                Director.Dao.getEffectList({directorId: entity.id, type: type}, function (data) {
                    if (data != null && data.code == "A00000") {
                        makeEffectList(type, data.data);

                        switch (type) {
                            case 1:
                                config.PageBeanEffectImage.setNewData(data.data);
                                bindEffectImageEvent();
                                break;
                            case 2:
                                config.PageBeanEffectSubtitle.setNewData(data.data);
                                break;
                            case 3:
                                config.PageBeanEffectAnimation.setNewData(data.data);
                                break;
                            case 4:
                                config.PageBeanEffectAudio.setNewData(data.data);
                                bindEffectAudioEvent();
                                break;
                            case 5:
                                config.PageBeanEffectCover.setNewData(data.data);
                                break;

                        }
                    }
                })

            }


            function makeEffectList(type,data) {

                var container = null,
                    content = "";

                var htmlArr = [];

                switch (type) {
                    case 1:
                        container = $("#effect-images");
                        break;
                    case 2:
                        container = $("#effect-subtitles");
                        break;
                    case 3:
                        container = $("#effect-animations");
                        break;
                    case 4:
                        container = $("#effect-audios");
                        break;
                    case 5:
                        container = $("#effect-covers");
                        break;

                }
                $.each(data, function (index, e) {
                    htmlArr.push(makeUpEffectDiv(e, type));
                });

                htmlArr.push(makeUpEffectAddDiv(type));

                content = htmlArr.join('');

                container.html(content);

            }

            function makeUpEffectDiv(e, type) {
                var options = encodeURIComponent(JSON.stringify(e));
                var htmlArr = [];
                switch (type) {
                    case 1:
                        if (e.status == "1") {
                            htmlArr.push(' <div data-div-id="' + e.id + '" data=' + options + ' class="effect_element_div">');
                            htmlArr.push(' <div class="effect_container"><div class="effect_upper">');
                            htmlArr.push(' <label style="padding-top: 20px;">');
                            htmlArr.push(' <img class="effect_playing" src="img/u311.png" alt="">正在播出...');
                            htmlArr.push(' </label>');
                            htmlArr.push(' <button class="d-btn effect_stop" onclick="Director.Util.submitStopPlayEffect(this, 1)" data-id="' + e.id + '">停止</button>');
                            htmlArr.push(' </div>')
                            htmlArr.push(' <img class="content" src="' + e.url + '">');
                            htmlArr.push(' </div>')
                            htmlArr.push(' <input type="text" value="' + e.name + '" data-id="' + e.id + '" onblur="Director.Util.updateEffectName(this)" onkeyup="Director.Util.updateEffectNameShortCut(event)">');
                            htmlArr.push(' </div>');
                        } else {
                            htmlArr.push(' <div data-div-id="' + e.id + '" data=' + options + ' class="effect_element_div">');
                            htmlArr.push(' <div style="" data-id="' + e.id + '">');
                            htmlArr.push(' <img class="change" src="img/director/edit.png" data-id="' + e.id + '" onclick="Director.Util.editEffectShow(this, 1)">');
                            htmlArr.push(' <img class="preview" src="img/effectPreview.png" data-id="' + e.id + '" onclick="Director.Util.previewEffect(this)">');
                            htmlArr.push(' <img class="play" src="img/effectPlay.png" data-id="' + e.id + '" onclick="Director.Util.submitPlayEffect(this, 1)">');
                            htmlArr.push(' <img class="del" src="img/director/delete.png" data-id="' + e.id + '" onclick="Director.Util.delEffect(this, 1)">');
                            //htmlArr.push(' <img class="start" src="img/u618.png" data-id="2" onclick="Director.Util.doResourceSwitch(this)">');
                            //htmlArr.push(' <span onclick="Director.Util.delEffect(this, ' + e.type + ')" data-id="' + e.id + '">X</span>');
                            htmlArr.push(' <img class="content" src="' + e.url + '">');
                            htmlArr.push(' </div>');
                            htmlArr.push(' <input type="text" value="' + e.name + '" data-id="' + e.id + '" onblur="Director.Util.updateEffectName(this)" onkeyup="Director.Util.updateEffectNameShortCut(event)">');
                            htmlArr.push(' </div>');
                        }
                        break;
                    case 2:
                        if (e.url.length > 32) {
                            e.url = e.url.slice(0, 32) + ' ...';
                        }
                        if (e.status == "1") {
                            htmlArr.push(' <div data-div-id="' + e.id + '" data=' + options + ' class="effect_subtitle_div" stype="position: relative;">');
                            htmlArr.push(' <span style="float:left;margin-top:8px;">' + e.url + '</span>');
                            htmlArr.push(' <div class="effect_upper"><div class="effect_hint">');
                            htmlArr.push(' <img class="effect_playing" src="img/u311.png" alt="">正在播出...');
                            htmlArr.push(' </div>');
                            htmlArr.push(' <button class="d-btn effect_stop" onclick="Director.Util.submitStopPlayEffect(this, 2)" data-id="' + e.id + '">停止</button>');
                            htmlArr.push(' </div></div>');
                        } else {
                            htmlArr.push(' <div style="position:relative;" data-div-id="' + e.id + '" data=' + options + ' class="effect_subtitle_div" data-id="' + e.id + '">');
                            htmlArr.push(' <span style="position:absolute;margin-top:8px;">' + e.url + '</span>');
                            htmlArr.push(' <div style="position:absolute;right:0px;margin-top:8px;background:#e7f0f7;">');
                            htmlArr.push(' <img class="preview" src="img/effectPreview.png" data-id="' + e.id + '" onclick="Director.Util.previewEffect(this)">');
                            htmlArr.push(' <img class="play" src="img/effectPlay.png" data-id="' + e.id + '" onclick="Director.Util.submitPlayEffect(this, 2)">');
                            htmlArr.push(' <img class="change" src="img/director/edit.png" data-id="' + e.id + '" onclick="Director.Util.editEffectShow(this, 2)">');
                            htmlArr.push(' <img class="del" src="img/director/delete.png" data-id="' + e.id + '" onclick="Director.Util.delEffect(this, 2)">');
                            htmlArr.push(' </div></div>');
                        }
                        break;
                    case 3:
                        var extraInfo = e.extraInfo != "" ? JSON.parse(e.extraInfo) : {};
                        var imageUrl = extraInfo['foreground'] || "img/default_animation.png";
                        if (e.status == "1") {
                            htmlArr.push(' <div data-div-id="' + e.id + '" data=' + options + ' class="effect_element_div">');
                            htmlArr.push(' <div class="effect_container"><div class="effect_upper">');
                            htmlArr.push(' <label style="padding-top: 20px;">');
                            htmlArr.push(' <img class="effect_playing" src="img/u311.png" alt="">正在播出...');
                            htmlArr.push(' </label>');
                            htmlArr.push(' <button class="d-btn effect_stop" onclick="Director.Util.submitStopPlayEffect(this, 3)" data-id="' + e.id + '">停止</button>');
                            htmlArr.push(' </div>')
                            htmlArr.push(' <img class="content" src="' + imageUrl + '">');
                            htmlArr.push(' </div>')
                            htmlArr.push(' <input type="text" value="' + e.name + '" data-id="' + e.id + '" onblur="Director.Util.updateEffectName(this)" onkeyup="Director.Util.updateEffectNameShortCut(event)">');
                            htmlArr.push(' </div>');
                        } else {
                            htmlArr.push(' <div data-div-id="' + e.id + '" data=' + options + ' class="effect_element_div">');
                            htmlArr.push(' <div style="">');
                            htmlArr.push(' <img class="change" src="img/director/edit.png" data-id="' + e.id + '" onclick="Director.Util.editEffectShow(this, 3)">');
                            htmlArr.push(' <img class="preview" src="img/effectPreview.png" data-id="' + e.id + '" onclick="Director.Util.previewAnimationEffect(this)">');
                            htmlArr.push(' <img class="play" src="img/effectPlay.png" data-id="' + e.id + '" onclick="Director.Util.submitPlayEffect(this, 3)">');
                            //htmlArr.push(' <img class="start" src="img/u618.png" data-id="2" onclick="Director.Util.doResourceSwitch(this)">');
                            htmlArr.push(' <img class="del" src="img/director/delete.png" data-id="' + e.id + '" onclick="Director.Util.delEffect(this, 3)">');
                            htmlArr.push(' <img class="content" src="' + imageUrl + '">');
                            htmlArr.push(' </div>');
                            htmlArr.push(' <input type="text" value="' + e.name + '" data-id="' + e.id + '" onblur="Director.Util.updateEffectName(this)" onkeyup="Director.Util.updateEffectNameShortCut(event)">');
                            htmlArr.push(' </div>');

                        }
                        break;
                    case 4:
                        var extraInfo = e.extraInfo != "" ? JSON.parse(e.extraInfo) : {};
                        var volumn = extraInfo['volumn'] || '0';
                        htmlArr.push(' <div data-div-id="' + e.id + '" data=' + options + ' class="effect_audio_div">');
                        htmlArr.push(' <div style="position: relative;">');
                        htmlArr.push(' <input class="volumn-range" data-id="' + e.id + '" type="range" min="0" max="100" value="' + volumn + '" onchange="Director.Util.changeVolumn(this)"/>')
                        htmlArr.push(' <button class="d-btn d-btn-primary play" data-id="' + e.id + '" onclick="Director.Util.submitPlayEffect(this, 4)">播出</button>');
                        //htmlArr.push(' <img class="change" src="img/u128.png" data-id="' + e.id + '" onclick="Director.Util.editEffectShow(this, 4)">');
                        //htmlArr.push(' <img class="start" src="img/u618.png" data-id="2" onclick="Director.Util.doResourceSwitch(this)">');
                        htmlArr.push(' <img class="del" src="img/director/delete.png" data-id="' + e.id + '" onclick="Director.Util.delEffect(this, 4)">');
                        htmlArr.push(' <img class="content" src="img/default_audio.png">');
                        htmlArr.push(' </div>');
                        //htmlArr.push(' <input class="volumn-range" data-id="' + e.id + '" type="range" min="0" max="100" value="' + volumn + '" onchange="Director.Util.changeVolumn(this)" style="margin-bottom: 10px;width:164px;" />')
                        htmlArr.push(' <input type="text" value="' + e.name + '" data-id="' + e.id + '" onblur="Director.Util.updateEffectName(this)" onkeyup="Director.Util.updateEffectNameShortCut(event)">');
                        htmlArr.push(' </div>');
                        break;
                    case 5:
                        if (e.status == "1") {
                            htmlArr.push(' <div data-div-id="' + e.id + '" data=' + options + ' class="effect_element_div">');
                            htmlArr.push(' <div class="effect_container"><div class="effect_upper">');
                            htmlArr.push(' <label style="padding-top: 20px;">');
                            htmlArr.push(' <img class="effect_playing" src="img/u311.png" alt="">正在播出...');
                            htmlArr.push(' </label>');
                            htmlArr.push(' <button class="d-btn effect_stop" onclick="Director.Util.submitStopPlayEffect(this, 5)" data-id="' + e.id + '">停止</button>');
                            htmlArr.push(' </div>')
                            if (e.url.trim().length > 0) {
                                htmlArr.push(' <img class="content" src="' + e.url + '">');
                            } else {
                                htmlArr.push(' <img class="content" src="img/director/effect_cover.png">');
                            }
                            htmlArr.push(' </div>')
                            if (e.name.trim().length > 0) {
                                htmlArr.push(' <input type="text" value="' + e.name + '" data-id="' + e.id + '" onblur="Director.Util.updateEffectName(this)" onkeyup="Director.Util.updateEffectNameShortCut(event)">');
                            } else {
                                htmlArr.push(' <input type="text" value="遮标' + e.id + '" data-id="' + e.id + '" onblur="Director.Util.updateEffectName(this)" onkeyup="Director.Util.updateEffectNameShortCut(event)">');
                            }
                            htmlArr.push(' </div>');
                        } else {
                            htmlArr.push(' <div data-div-id="' + e.id + '" data=' + options + ' class="effect_element_div">');
                            htmlArr.push(' <div style="" data-id="' + e.id + '">');
                            htmlArr.push(' <img class="change" src="img/director/edit.png" data-id="' + e.id + '" onclick="Director.Util.editEffectShow(this, 5)">');
                            htmlArr.push(' <img class="preview" src="img/effectPreview.png" data-id="' + e.id + '" onclick="Director.Util.previewEffect(this)">');
                            htmlArr.push(' <img class="play" src="img/effectPlay.png" data-id="' + e.id + '" onclick="Director.Util.submitPlayEffect(this, 5)">');
                            htmlArr.push(' <img class="del" src="img/director/delete.png" data-id="' + e.id + '" onclick="Director.Util.delEffect(this, 5)">');
                            //htmlArr.push(' <img class="start" src="img/u618.png" data-id="2" onclick="Director.Util.doResourceSwitch(this)">');
                            //htmlArr.push(' <span onclick="Director.Util.delEffect(this, ' + e.type + ')" data-id="' + e.id + '">X</span>');
                            if (e.url.trim().length > 0) {
                                htmlArr.push(' <img class="content" src="' + e.url + '">');
                            } else {
                                htmlArr.push(' <img class="content" src="img/director/effect_cover.png">');
                            }
                            htmlArr.push(' </div>');
                            if (e.name.trim().length > 0) {
                                htmlArr.push(' <input type="text" value="' + e.name + '" data-id="' + e.id + '" onblur="Director.Util.updateEffectName(this)" onkeyup="Director.Util.updateEffectNameShortCut(event)">');
                            } else {
                                htmlArr.push(' <input type="text" value="遮标' + e.id + '" data-id="' + e.id + '" onblur="Director.Util.updateEffectName(this)" onkeyup="Director.Util.updateEffectNameShortCut(event)">');
                            }

                            htmlArr.push(' </div>');
                        }
                        break;

                }

                return htmlArr.join("");
            }


            function makeUpEffectAddDiv(type) {
                var htmlArr = [];
                switch (type) {
                    case 1:
                        htmlArr.push('<div class="effect_element_div"><div style="border:1px solid #aabcc7;text-align: center;">');
                        htmlArr.push('<label for="effect_img_file_input">');
                        htmlArr.push('<img style="margin-top: 10px;" src="img/addSourceBtn.png">');
                        htmlArr.push('</label>');
                        htmlArr.push('<input id="effect_img_file_input" type="file" style="display:none" class="uploadBtn"/>')
                        htmlArr.push('</div></div>');
                        break;
                    case 3:
                        htmlArr.push('<div class="effect_element_div"><div style="border:1px solid #aabcc7;text-align: center;">');
                        htmlArr.push('<label>');
                        htmlArr.push('<img style="margin-top: 10px;" src="img/addSourceBtn.png" onclick="Director.Effect.AddAnimationShow();">');
                        htmlArr.push('</label>');
                        htmlArr.push('</div></div>');
                        break;
                    case 4:
                        htmlArr.push('<div class="effect_element_div"><div style="border:1px solid #aabcc7;text-align: center;">');
                        htmlArr.push('<label for="effect_audio_file_input">');
                        htmlArr.push('<img style="margin-top: 10px;" src="img/addSourceBtn.png">');
                        htmlArr.push('</label>');
                        htmlArr.push('<input id="effect_audio_file_input" type="file" style="display:none" class="uploadBtn" accept="audio/mpeg"/>')
                        htmlArr.push('</div></div>');
                        break;
                    case 5:
                        htmlArr.push('<div class="effect_element_div"><div style="border:1px solid #aabcc7;text-align: center;">');
                        htmlArr.push('<label>');
                        htmlArr.push('<img style="margin-top: 10px;" src="img/addSourceBtn.png" onclick="Director.Effect.AddCoverShow();">');
                        htmlArr.push('</label>');
                        htmlArr.push('</div></div>');
                        break;

                }

                return htmlArr.join("");
            }

            function bindEffectImageEvent() {
                var $imageArea = $("#effect-tabs-1");
                //$subtitleArea = $("#effect-tabs-2"),
                //$animationArea = $("#effect-tabs-3"),
                //$audioArea = $("#effect-tabs-4");

                var $imageUploadBtn = $imageArea.find("input.uploadBtn");
                var imageParent = $("#dlg_edit_image");
                $imageUploadBtn.val("");
                $imageUploadBtn.bind("click", function (event) {
                    console.log("click");
                });
                $imageUploadBtn.bind("change", function (e) {
                    var file = e.target.files[0];
                    var url = Com.file.getObjectURL(file)

                    var params = config.EffectUploadCommonParams;

                    params.business_type = "image";
                    params.file_type = Com.file.getExt(file.name);
                    params.file_size = file.size;

                    params.file = file;

                    $(this).val('');
                    // 判断上传素材是否是图片
                    if (!Director.Util.isValidImage(params.file_type)) {
                        EpgWeb.Plugin.showTips({content: "上传图片格式只支持png, jpg, bmp, gif, 请重新上传", type: "error"})
                        return;
                    }


                    startUploadFile(params, AddEffectImage);

                });
            }

            function bindEffectAudioEvent() {
                var $audioArea = $("#effect-tabs-4");

                var $audioUploadBtn = $audioArea.find("input.uploadBtn");
                $audioUploadBtn.val('');
                $audioUploadBtn.bind("click", function (event) {
                    console.log("click");
                });
                $audioUploadBtn.bind("change", function (e) {
                    var file = e.target.files[0];
                    var url = Com.file.getObjectURL(file)

                    var params = config.EffectUploadCommonParams;

                    params.business_type = "audio";
                    params.file_type = Com.file.getExt(file.name);
                    params.file_size = file.size;

                    params.file = file;

                    $(this).val('');
                    // 判断上传素材是否是音频
                    if (!Director.Util.isValidAudio(params.file_type)) {
                        EpgWeb.Plugin.showTips({content: "上传音频格式只支持mp3, 请重新上传", type: "error"})
                        return;
                    }

                    startUploadFile(params, AddEffectAudio);

                });
            }

            function bindEffectEvent() {
                console.log("bindEffectEvent!!!!");
                var $imageArea = $("#effect-tabs-1"),
                    $subtitleArea = $("#effect-tabs-2"),
                    $animationArea = $("#effect-tabs-3"),
                    $audioArea = $("#effect-tabs-4");

                var $imageUploadBtn = $imageArea.find("input.uploadBtn");
                var imageParent = $("#dlg_edit_image");
                $imageUploadBtn.val("");
                $imageUploadBtn.bind("click", function (event) {
                    console.log("click");
                });
                $imageUploadBtn.bind("change", function (e) {
                    var file = e.target.files[0];
                    var url = Com.file.getObjectURL(file)

                    var params = config.EffectUploadCommonParams;

                    params.business_type = "image";
                    params.file_type = Com.file.getExt(file.name);
                    params.file_size = file.size;

                    params.file = file;

                    $(this).val('');
                    // 判断上传素材是否是图片
                    if (!Director.Util.isValidImage(params.file_type)) {
                        EpgWeb.Plugin.showTips({content: "上传图片格式只支持png, jpg, bmp, gif, 请重新上传", type: "error"})
                        return;
                    }


                    startUploadFile(params, AddEffectImage);

                });

                var loopCheckbox = imageParent.find('input[name=loop]');
                loopCheckbox.bind('change', function (e) {
                    var target = $(e.target);
                    var loopDiv = imageParent.find('#effect-image-loop-div');
                    if (target.is(":checked")) {
                        loopDiv.show();
                    } else {
                        loopDiv.hide();
                    }
                });

                var imageAnmiationSelect = imageParent.find('select[name=animation]');
                imageAnmiationSelect.bind('change', function (e) {
                    var target = $(e.target);
                    var timesDiv = imageParent.find('#effect-image-times-div');
                    if (target.val() == "0") {
                        timesDiv.hide();
                    } else {
                        timesDiv.show();
                    }
                });

                //imageAnmiationSelect.click();

                var $subtitleAddBtn = $subtitleArea.find("button.btnAdd");
                $subtitleAddBtn.bind("click", function (e) {
                    AddSubtitleShow();
                });

                var subtitleParent = $('#dlg_edit_subtitle');
                var uploadSubtitleButton = subtitleParent.find('input.uploadBtn');
                uploadSubtitleButton.bind("change", function (e) {
                    var file = e.target.files[0];
                    var url = Com.file.getObjectURL(file)

                    var params = config.EffectUploadCommonParams;

                    params.business_type = "image";
                    params.file_type = Com.file.getExt(file.name);
                    params.file_size = file.size;

                    params.file = file;

                    $(this).val('');
                    // 判断上传素材是否是图片
                    if (!Director.Util.isValidImage(params.file_type)) {
                        EpgWeb.Plugin.showTips({content: "上传图片格式只支持png, jpg, bmp, gif, 请重新上传", type: "error"})
                        return;
                    }

                    var img = new Image();
                    img.onload = function () {
                        if (img.width != 1920 || img.height != 70) {
                            EpgWeb.Plugin.showTips({content: "只支持1920X70的图片，请重新上传", type: "error"})
                        } else {
                            startUploadFile(params, Director.Util.AddSubtitleBackground);
                        }
                    }

                    img.src = url;

                });

                var subtitleEffectChangeList = ['select[name=fontName]', 'select[name=fontSize]', 'input[name=fontColor]'];
                $.each(subtitleEffectChangeList, function (i, e) {
                    subtitleParent.find(e).bind("change", function () {
                        dialogSubtitlePreview();
                    })
                });

                //var fontArrays = ['fontBold', 'fontItalic', 'fontUnderline'];
                var fontArrays = ['fontBold'];
                $.each(fontArrays, function (i, e) {
                    var a = subtitleParent.find('a.' + e);
                    a.bind('click', function (event) {
                        $(this).toggleClass('active');
                        $(this).find('input').val($(this).hasClass('active') ? 1 : 0);
                        dialogSubtitlePreview();
                    })
                });

                var subtitleLoopCheckbox = subtitleParent.find('input[name=loop]');
                subtitleLoopCheckbox.bind('change', function (e) {
                    var target = $(e.target);
                    var loopDiv = subtitleParent.find('#effect-subtitle-loop-div');
                    if (target.is(":checked")) {
                        loopDiv.show();
                    } else {
                        loopDiv.hide();
                    }
                });

                var subtitleHorseCheckbox = subtitleParent.find('input[name=horseLamp]');
                subtitleHorseCheckbox.bind('change', function (e) {
                    var target = $(e.target);
                    var loopDiv = subtitleParent.find('#effect-subtitle-loop-container-div');
                    if (target.is(":checked")) {
                        loopDiv.show();
                    } else {
                        loopDiv.hide();
                    }
                });

                var $animationAddBtn = $animationArea.find("button.btnAdd");
                $animationAddBtn.bind("click", function (e) {
                    AddAnimationShow();
                });
                var animationParent = $('#dlg_edit_animation');
                var uploadAUrlBtn = animationParent.find('input.uploadBtnUrl');
                var uploadAForegroundBtn = animationParent.find('input.uploadBtnForeground');
                uploadAUrlBtn.bind("change", function (e) {
                    var file = e.target.files[0];
                    var url = Com.file.getObjectURL(file)

                    var params = config.EffectUploadCommonParams;

                    params.business_type = "video";
                    params.file_type = Com.file.getExt(file.name);
                    params.file_size = file.size;

                    params.file = file;

                    $(this).val('');
                    // 判断上传素材是否是视频
                    if (!Director.Util.isValidVideo(params.file_type)) {
                        EpgWeb.Plugin.showTips({content: "上传动画格式只支持mov, 请重新上传", type: "error"})
                        return;
                    }

                    startUploadFile(params, AddAnimationUrl);
                });

                uploadAForegroundBtn.bind("change", function (e) {
                    var file = e.target.files[0];
                    var url = Com.file.getObjectURL(file)

                    var params = config.EffectUploadCommonParams;

                    params.business_type = "image";
                    params.file_type = Com.file.getExt(file.name);
                    params.file_size = file.size;

                    params.file = file;

                    $(this).val('');
                    // 判断上传素材是否是图片
                    if (!Director.Util.isValidImage(params.file_type)) {
                        EpgWeb.Plugin.showTips({content: "上传图片格式只支持png, jpg, bmp, gif, 请重新上传", type: "error"})
                        return;
                    }

                    startUploadFile(params, AddAnimationForeground);
                });

                var animationLoopCheckbox = animationParent.find('input[name=loop]');
                animationLoopCheckbox.bind('change', function (e) {
                    var target = $(e.target);
                    var loopDiv = animationParent.find('#effect-animation-loop-div');
                    if (target.is(":checked")) {
                        loopDiv.show();
                    } else {
                        loopDiv.hide();
                    }
                });

                var $audioUploadBtn = $audioArea.find("input.uploadBtn");
                $audioUploadBtn.val('');
                $audioUploadBtn.bind("click", function (event) {
                    console.log("click");
                });
                $audioUploadBtn.bind("change", function (e) {
                    var file = e.target.files[0];
                    var url = Com.file.getObjectURL(file)

                    var params = config.EffectUploadCommonParams;

                    params.business_type = "audio";
                    params.file_type = Com.file.getExt(file.name);
                    params.file_size = file.size;

                    params.file = file;

                    $(this).val('');
                    // 判断上传素材是否是音频
                    if (!Director.Util.isValidAudio(params.file_type)) {
                        EpgWeb.Plugin.showTips({content: "上传音频格式只支持mp3, 请重新上传", type: "error"})
                        return;
                    }

                    startUploadFile(params, AddEffectAudio);

                });


            }

            function refreshEffectList(type) {
                getEffectList(type);
            }

            function startUploadFile(params, callback) {
                var url = config.EFFECT_UPLOAD_URL;
                url = url + "?t=1";

                $.each(params, function (k, v) {
                    url = url + "&" + k + "=" + v;
                });

                $.ajax({
                    url: url,
                    method: "post",
                    cache: false,
                    contentType: false,
                    processData: false,
                    xhr: function () {
                        var xhr = jQuery.ajaxSettings.xhr();
                        return xhr;
                    },
                    data: params.file,
                    success: function (data) {
                        if (data.code == "A00000") {
                            console.log("success upload");
                            callback.call(this, data.data, params);
                        }
                    },
                    error: function (data) {

                    }
                })
            }

            function AddEffectImage(data, params) {
                var element = config.EFFECT_DEFAULTS['image'];

                var entity = Director.Util.getEntity();

                element.directorId = entity.id;
                element.programQipuId = entity.programQipuId;
                element.url = data.httpInnerUrl;
                element.type = 1;
                element.name = params.file.name;

                element = JSON.stringify(element);

                Director.Dao.addEffect({'data': element}, function (data) {
                    if (data != null && data.code == "A00000") {
                        refreshEffectList(1);
                    }
                })
            }

            function AddEffectAudio(data, params) {
                var element = {};

                var entity = Director.Util.getEntity();

                element.directorId = entity.id;
                element.programQipuId = entity.programQipuId;
                element.url = data.httpInnerUrl;
                element.type = 4;
                element.name = params.file.name;
                element.location = '';
                element.extraInfo = '{"volumn":20}';

                element = JSON.stringify(element);

                Director.Dao.addEffect({'data': element}, function (data) {
                    if (data != null && data.code == "A00000") {
                        refreshEffectList(4);
                    }
                })
            }

            function AddSubtitleShow() {
                var parent = $("#dlg_edit_subtitle");
                var $form = parent.find('form[name="basicForm"]');
                Director.Util.clearForm($form);
                parent.dialog('option', 'title', '添加字幕').dialog("open");


                if ($form.find('input[name=loop]').is(":checked")) {
                    $form.find('#effect-subtitle-loop-div').show();
                } else {
                    $form.find('#effect-subtitle-loop-div').hide();
                }

                if ($form.find('input[name=horseLamp]').is(":checked")) {
                    $form.find('#effect-subtitle-loop-container-div').show();
                } else {
                    $form.find('#effect-subtitle-loop-container-div').hide();
                }

                $form.find('select[name=fontSize]').val("15");


                dialogSubtitlePreview();
            }

            function dialogSubtitlePreview() {
                var parent = $('#dlg_edit_subtitle');
                var content = parent.find("textarea[name=content]");
                var fontName = parent.find('select[name=fontName]');
                var fontSize = parent.find('select[name=fontSize]');
                var fontColor = parent.find('input[name=fontColor]');
                var fontBold = parent.find('input[name=fontBold]');

                var styles = {
                    "font-family": fontName.find('option:selected').text(),
                    "font-size": fontSize.val() + "px",
                    "line-height": fontSize.val() + "px",
                    "font-weight": fontBold.val() == "1" ? "bold" : "normal",
                    "color": fontColor.val()
                }

                content.css(styles);

            }

            function AddAnimationShow() {
                var parent = $("#dlg_edit_animation");
                var $form = parent.find('form[name="basicForm"]');
                Director.Util.clearForm($form);
                parent.dialog('option', 'title', '添加动画').dialog("open");

                $form.find('#form_animation_url').show();

                if ($form.find('input[name=loop]').is(":checked")) {
                    $form.find('#effect-animation-loop-div').show();
                } else {
                    $form.find('#effect-animation-loop-div').hide();
                }
            }
            function AddCoverShow() {
                var parent = $("#dlg_edit_cover");
                var $form = parent.find('form[name="basicForm"]');
                Director.Util.clearForm($form);
                parent.dialog('option', 'title', '遮标编辑').dialog("open");

            }
            function AddAnimationUrl(data, params) {
                var parent = $("#dlg_edit_animation");
                var $background = parent.find('input[name=url]');
                var myname = parent.find('input[name=myname]');
                $background.val(data.httpInnerUrl);
                myname.val(params.file.name);
            }

            function AddAnimationForeground(data, params) {
                var parent = $("#dlg_edit_animation");
                var $background = parent.find('input[name=foreground]');
                $background.val(data.httpInnerUrl);
            }


            return {
                init: init,
                getEffectList:getEffectList,
                makeEffectList:makeEffectList,
                makeUpEffectDiv:makeUpEffectDiv,
                makeUpEffectAddDiv:makeUpEffectAddDiv,
                bindEffectImageEvent:bindEffectImageEvent,
                bindEffectAudioEvent:bindEffectAudioEvent,
                bindEffectEvent:bindEffectEvent,
                refreshEffectList:refreshEffectList,
                startUploadFile:startUploadFile,
                AddEffectImage:AddEffectImage,
                AddEffectAudio:AddEffectAudio,
                AddSubtitleShow:AddSubtitleShow,
                dialogSubtitlePreview:dialogSubtitlePreview,
                AddAnimationShow:AddAnimationShow,
                AddCoverShow:AddCoverShow,
                AddAnimationUrl:AddAnimationUrl,
                AddAnimationForeground:AddAnimationForeground,
            };

        })()
    }
);